package ru.rchervot.sanasar.client.view;

import ru.rchervot.sanasar.client.i18n.I18nConstants;
import ru.rchervot.sanasar.client.place.PlaceSearchCandidates;
import ru.rchervot.sanasar.client.place.PlaceSettings;

import com.google.gwt.core.client.GWT;
import com.google.gwt.user.client.ui.Composite;
import com.google.gwt.user.client.ui.HasHorizontalAlignment;
import com.google.gwt.user.client.ui.HasVerticalAlignment;
import com.google.gwt.user.client.ui.HorizontalPanel;
import com.google.gwt.user.client.ui.Hyperlink;
import com.google.gwt.user.client.ui.Label;
import com.google.gwt.user.client.ui.Widget;

public class HeaderViewDefault extends Composite implements HeaderPresenterDefault.Display {
	private final HorizontalPanel basePanel = new HorizontalPanel();
	private final Hyperlink linkHelp = new Hyperlink();
	private final Hyperlink linkLogout = new Hyperlink();
	
	private final Hyperlink linkCandidates = new Hyperlink();
	private final Hyperlink linkCompanies = new Hyperlink();
	private final Hyperlink linkOrders = new Hyperlink();
	private final Hyperlink linkSettings = new Hyperlink();
	private final Hyperlink linkReports = new Hyperlink();
	
	private final Label labelCandidates = new Label();
	private final Label labelCompanies = new Label();
	private final Label labelOrders = new Label();
	private final Label labelReports = new Label();
	
	private final Label username = new Label("test@test.com");
	private final static String DELIMITER = "|";
	
	private Presenter presenter;
	protected I18nConstants constants = GWT.create(I18nConstants.class);
	
	private final Widget connectionInfo;
	
	public HeaderViewDefault(Widget connectionInfo) {
		this.connectionInfo = connectionInfo;
		
		linkCandidates.setTargetHistoryToken(PlaceSearchCandidates.historyTokenDefault());
		linkSettings.setTargetHistoryToken(PlaceSettings.historyTokenDefault());
		
		linkCandidates.setText(constants.HeaderLinkAndLabelCandidates());
		linkCompanies.setText(constants.HeaderLinkAndLabelCompanies());
		linkOrders.setText(constants.HeaderLinkAndLabelOrders());
		linkReports.setText(constants.HeaderLinkAndLabelReports());
		linkSettings.setText(constants.HeaderLinkAndLabelSettings());
		linkHelp.setText(constants.HeaderLinkHelp());
		linkLogout.setText(constants.HeaderLinkLogout());
		
		labelCandidates.setText(constants.HeaderLinkAndLabelCandidates());
		labelCompanies.setText(constants.HeaderLinkAndLabelCompanies());
		labelOrders.setText(constants.HeaderLinkAndLabelOrders());
		labelReports.setText(constants.HeaderLinkAndLabelReports());
		
		labelCandidates.setStylePrimaryName("HeaderViewDefault_label");
		labelCompanies.setStylePrimaryName("HeaderViewDefault_label");
		labelOrders.setStylePrimaryName("HeaderViewDefault_label");
		labelReports.setStylePrimaryName("HeaderViewDefault_label");
		
		HorizontalPanel hpRight = new HorizontalPanel();
		hpRight.setStylePrimaryName("HeaderViewDefault_pRight");
		
		HorizontalPanel hpLeft = new HorizontalPanel();
		hpLeft.setStylePrimaryName("HeaderViewDefault_pLeft");
		
		basePanel.setStylePrimaryName("HeaderViewDefault");
		basePanel.setVerticalAlignment(HasVerticalAlignment.ALIGN_MIDDLE);
		basePanel.add(hpLeft);
		basePanel.setCellHorizontalAlignment(hpLeft,
				HasHorizontalAlignment.ALIGN_LEFT);
		basePanel.add(hpRight);
		basePanel.setCellHorizontalAlignment(hpRight,
				HasHorizontalAlignment.ALIGN_RIGHT);
		basePanel.setSize("100%", Constants.kHeaderHeight + "px");
		
		username.setStylePrimaryName("HeaderViewDefault_username");
		
		hpRight.add(username);
		hpRight.add(new Label(DELIMITER));
		hpRight.add(linkSettings);
		hpRight.add(new Label(DELIMITER));
		hpRight.add(linkHelp);
		hpRight.add(new Label(DELIMITER));
		hpRight.add(linkLogout);
		
		hpLeft.add(linkCandidates);
		hpLeft.add(labelCandidates);
		hpLeft.add(linkCompanies);
		hpLeft.add(labelCompanies);
		hpLeft.add(linkOrders);
		hpLeft.add(labelOrders);
		hpLeft.add(linkReports);
		hpLeft.add(labelReports);
		
		this.initWidget(basePanel);
		this.setWidth("100%");
		
		basePanel.setVisible(false);
	}

	@Override
	public void setPresenter(Presenter presenter) {
		this.presenter = presenter;
	}
	
	@Override
	public void setModeCandidates() {
		basePanel.setVisible(true);
		
		
		linkCandidates.setVisible(false);
		labelCandidates.setVisible(true);
		
		linkCompanies.setVisible(true);
		labelCompanies.setVisible(false);
		
		linkOrders.setVisible(true);
		labelOrders.setVisible(false);
		
		linkReports.setVisible(true);
		labelReports.setVisible(false);
		
	} 
	
	@Override
	public void setModeCompanies() {
		basePanel.setVisible(true);
		
		
		linkCandidates.setVisible(true);
		labelCandidates.setVisible(false);
		
		linkCompanies.setVisible(false);
		labelCompanies.setVisible(true);
		
		linkOrders.setVisible(true);
		labelOrders.setVisible(false);
		
		linkReports.setVisible(true);
		labelReports.setVisible(false);
		
	}
	
	@Override
	public void setModeOrders() {
		basePanel.setVisible(true);
		
		
		linkCandidates.setVisible(true);
		labelCandidates.setVisible(false);
		
		linkCompanies.setVisible(true);
		labelCompanies.setVisible(false);
		
		linkOrders.setVisible(false);
		labelOrders.setVisible(true);
		
		linkReports.setVisible(true);
		labelReports.setVisible(false);
		
	} 
	
	@Override
	public void setModeReports() {
		basePanel.setVisible(true);
		
		
		linkCandidates.setVisible(true);
		labelCandidates.setVisible(false);
		
		linkCompanies.setVisible(true);
		labelCompanies.setVisible(false);
		
		linkOrders.setVisible(true);
		labelOrders.setVisible(false);
		
		linkReports.setVisible(false);
		labelReports.setVisible(true);
		
	} 
	
	@Override
	public void setModeSettings() {
		basePanel.setVisible(true);
		
		
		linkCandidates.setVisible(true);
		labelCandidates.setVisible(false);
		
		linkCompanies.setVisible(true);
		labelCompanies.setVisible(false);
		
		linkOrders.setVisible(true);
		labelOrders.setVisible(false);
		
		linkReports.setVisible(true);
		labelReports.setVisible(false);
		
	} 
	

}
